package com.bRoom.service.impl;

import com.bRoom.common.Conts;
import com.bRoom.common.ServerResponse;
import com.bRoom.dao.AdminMapper;
import com.bRoom.pojo.Admin;
import com.bRoom.service.IAdminService;
import com.bRoom.util.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service("iAdminService")
public class AdminServiceImpl implements IAdminService {

    @Autowired
    private AdminMapper adminMapper;

    public ServerResponse<Admin> addAdmin(Admin admin){
          if (admin!=null){
              admin.setAdminRole(Conts.ROLE.ROLE_SUPPER);
               int insertCount=adminMapper.insert(admin);
               if (insertCount>0){
                    return ServerResponse.createBySuccessMsg("添加成功");
               }
          }
          return ServerResponse.createByErrorMsg("添加失败");
    }

    public ServerResponse<Admin> updateAdmin(Admin admin){
          Admin updateCount =new Admin();
          updateCount.setAdminId(admin.getAdminId());
          updateCount.setAdminName(admin.getAdminName());
          updateCount.setAdminRole(admin.getAdminRole());
          String updateTime= DateTimeUtil.DatetoStr(new Date());
          updateCount.setUpdatetime(DateTimeUtil.StringToDate(updateTime));
          int updateCounts=adminMapper.updateByPrimaryKeySelective(updateCount);
          if (updateCounts>0){
               return ServerResponse.createBySuccessMsg("修改成功");
          }
          return ServerResponse.createByErrorMsg("修改失败");
    }


}
